package com.hlhj.funlike_business.activity;

import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.hlhj.funlike_business.R;
import com.hlhj.funlike_business.bean.MsgBean;
import com.hlhj.funlike_business.data.SPUser;
import com.hlhj.funlike_business.presenter.ShopNamePresenter;
import com.hlhj.funlike_business.views.ShopNameView;

import org.greenrobot.eventbus.EventBus;
import org.jetbrains.annotations.NotNull;

public class ShopNameAty extends BaseActivity<ShopNameView,ShopNamePresenter> implements ShopNameView {

    private ImageView img_back;
    private TextView tv_title,btn_ok;
    private EditText edit_name;
    private String name;

    @Override
    protected int getContentId() {
        return R.layout.aty_shopname;
    }

    @Override
    protected void initData() {
        tv_title.setText("店铺名称");
        name = getIntent().getStringExtra("name");
    }

    @NotNull
    @Override
    public ShopNameView bindView() {
        return this;
    }

    @NotNull
    @Override
    public ShopNamePresenter createPresenter() {
        return new ShopNamePresenter();
    }

    @Override
    public void initView() {
        tv_title =findViewById(R.id.tv_title);
        img_back =findViewById(R.id.img_back);
        btn_ok =findViewById(R.id.btn_ok);
        edit_name =findViewById(R.id.edit_name);
    }

    @Override
    public void logicStart() {
        edit_name.setText(name);
    }

    @Override
    public void setListener() {
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        btn_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != edit_name.getText().toString() || !"".equals(edit_name.getText().toString())){
                    getPresenter().LoadResult(ShopNameAty.this,edit_name.getText().toString());
                }else {
                    Toast.makeText(ShopNameAty.this,"请输入内容",Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    @Override
    public void showShopName(MsgBean msgBean) {
        new SPUser(getApplication()).setShopName(edit_name.getText().toString());
        Toast.makeText(this,msgBean.getMsg().toString(),Toast.LENGTH_SHORT).show();
        EventBus.getDefault().post("刷新");
        finish();
    }
}
